<template>
  <div class="app-container">
    <h3>学生信息</h3>
    <el-form :inline="true">
      <el-form-item label="学生ID">
        <el-input :disabled="true" :value="plan.user_info.uid" />
      </el-form-item>
      <el-form-item label="用户姓名/昵称">
        <el-input :disabled="true" :value="plan.user_info.name+'/'+plan.user_info.nick_name" />
      </el-form-item>
      <el-form-item label="年级">
        <el-input :disabled="true" :value="plan.user_info.grade.grade_name" />
      </el-form-item>
      <el-form-item label="班级">
        <el-input :disabled="true" :value="plan.user_info.class_name" />
      </el-form-item>
      <el-form-item label="测试时间">
        <el-input :disabled="true" :value="plan.create_time" />
      </el-form-item>
    </el-form>
    <el-form>
      <el-form-item label="意向专业选择">
        <el-tag v-for="(x,index) in majoring" :key="index" type="info"> {{ x }}</el-tag>
      </el-form-item>
      <el-form-item label="优势学科排序">
        <el-tag v-for="(x,index) in subjects" :key="index" type="info"> {{ x.subject }}</el-tag>
      </el-form-item>

      <el-form-item label="必选科目">
        <el-tag v-for="(x,index) in demands" :key="index" type="info"> {{ x }}</el-tag>
      </el-form-item>
    </el-form>
    <h3>最佳选课组合</h3>
    <el-form>
      <el-form-item v-for="(y,index) in plans" :key="index" :label="( index+1)+'号方案'">
        <el-tag v-for="(x,i) in y" :key="i" type="info"> {{ x }}</el-tag>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getXkBestPlan } from '../../api/statistics'

export default {
  data() {
    return {
      plan: {
        user_info: {
          grade: {},
          name: '',
          nick_name: ''
        },
        majoring: '',
        scheme: '[]',
        demand: '[]',
        ranking: '{}'
      }
    }
  },
  computed: {
    majoring() {
      return this.plan.majoring.split(',')
    },
    plans() {
      return JSON.parse(this.plan.scheme)
    },
    demands() {
      return JSON.parse(this.plan.demand)
    },
    subjects() {
      let maxNumList = []
      console.log(this.plan.ranking)
      const ranking = JSON.parse(this.plan.ranking)
      for (const x in ranking) {
        const newSubject = ranking[x]
        newSubject['subject'] = x
        maxNumList.push(newSubject)
      }
      maxNumList = maxNumList.sort((a, b) => {
        if (a.num < b.num) {
          return 1
        }
        if (a.num === b.num) {
          return 0
        }
        if (a.num > b.num) {
          return -1
        }
      })
      return maxNumList
    }
  },
  mounted() {
    this.getXkBestPlan()
  },
  methods: {
    getXkBestPlan() {
      const loading = this.$loading({
        text: '加载中',
        background: 'rgba(0,0,0,0.7)'
      })
      getXkBestPlan(this.$route.params.id).then(res => {
        console.log(res)
        this.plan = res
      }).finally(() => {
        loading.close()
      })
    }
  }
}
</script>

<style scoped>

</style>
